package cn.iocoder.yudao.module.xiaoBizHandler.service.tbErrorManagement;

import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;

import java.util.*;
import cn.iocoder.yudao.module.xiaoBizHandler.controller.admin.tbErrorManagement.vo.*;
import cn.iocoder.yudao.module.xiaoBizHandler.dal.dataobject.tbErrorManagement.XTbErrorManagementDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;

import cn.iocoder.yudao.module.xiaoBizHandler.convert.tbErrorManagement.XTbErrorManagementConvert;
import cn.iocoder.yudao.module.xiaoBizHandler.dal.mysql.tbErrorManagement.XTbErrorManagementMapper;

import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.xiaoBizHandler.enums.ErrorCodeConstants.*;

/**
 * 报错管理 Service 实现类
 *
 * @author xiaosy
 */
@Service
@Validated
public class XTbErrorManagementServiceImpl implements XTbErrorManagementService {

    @Resource
    private XTbErrorManagementMapper xTbErrorManagementMapper;

    @Override
    public String createXTbErrorManagement(XTbErrorManagementCreateReqVO createReqVO) {
        // 插入
        XTbErrorManagementDO xTbErrorManagement = XTbErrorManagementConvert.INSTANCE.convert(createReqVO);
        xTbErrorManagementMapper.insert(xTbErrorManagement);
        // 返回
        return xTbErrorManagement.getId();
    }

    @Override
    public void updateXTbErrorManagement(XTbErrorManagementUpdateReqVO updateReqVO) {
        // 校验存在
        this.validateXTbErrorManagementExists(updateReqVO.getId());
        // 更新
        XTbErrorManagementDO updateObj = XTbErrorManagementConvert.INSTANCE.convert(updateReqVO);
        xTbErrorManagementMapper.updateById(updateObj);
    }

    @Override
    public void deleteXTbErrorManagement(String id) {
        // 校验存在
        this.validateXTbErrorManagementExists(id);
        // 删除
        xTbErrorManagementMapper.deleteById(id);
    }

    private void validateXTbErrorManagementExists(String id) {
        if (xTbErrorManagementMapper.selectById(id) == null) {
            throw exception(XT_B_ERROR_MANAGEMENT_NOT_EXISTS);
        }
    }

    @Override
    public XTbErrorManagementDO getXTbErrorManagement(String id) {
        return xTbErrorManagementMapper.selectById(id);
    }

    @Override
    public List<XTbErrorManagementDO> getXTbErrorManagementList(Collection<String> ids) {
        return xTbErrorManagementMapper.selectBatchIds(ids);
    }

    @Override
    public PageResult<XTbErrorManagementDO> getXTbErrorManagementPage(XTbErrorManagementPageReqVO pageReqVO) {
        return xTbErrorManagementMapper.selectPage(pageReqVO);
    }

    @Override
    public List<XTbErrorManagementDO> getXTbErrorManagementList(XTbErrorManagementExportReqVO exportReqVO) {
        return xTbErrorManagementMapper.selectList(exportReqVO);
    }

}

